#include "agent.h"




Agent::Agent()
{
    pError = new STATE_ERROR();
    pIdle = new STATE_IDLE();
    pQueueEmpty = new STATE_QUEUE_EMPTY();
    pQueueFull = new STATE_QUEUE_FULL();
    pQueuePartyFull = new STATE_QUEUE_PARTY_FULL();
    pTerminated = new STATE_TERMINATED();
    pState = pTerminated;
}

Agent::~Agent()
{
    pState = nullptr;
    delete pError;
    delete pIdle;
    delete pQueueEmpty;
    delete pQueueFull;
    delete pQueuePartyFull;
    delete pTerminated;
}

void Agent::setSelfState(State *p)
{
    pState = p;
}

int Agent::check_transition_event_initialize()
{
    int err_code = pState->check_transition_event_initialize();
    return err_code;
}

int Agent::check_transition_event_terminate()
{
    int err_code = pState->check_transition_event_terminate();
    return err_code;
}

int Agent::check_transition_event_queue()
{
    int err_code = pState->check_transition_event_queue();
    return err_code;
}

int Agent::check_transition_event_queue_full()
{
    int err_code = pState->check_transition_event_queue_full();
    return err_code;
}

int Agent::check_transition_event_get_result()
{
    int err_code = pState->check_transition_event_get_result();
    return err_code;
}

int Agent::check_transition_event_get_result_empty()
{
    int err_code = pState->check_transition_event_get_result_empty();
    return err_code;
}

int Agent::check_transition_event_error()
{
    int err_code = pState->check_transition_event_error();
    return err_code;
}

int Agent::perform_transition_event_initialize()
{
    int err_code = 0;
    err_code = pState->perform_transition_event_initialize(this);
    return err_code;
}

int Agent::perform_transition_event_terminate()
{
    int err_code = 0;
    err_code = pState->perform_transition_event_terminate(this);
    return err_code;
}

int Agent::perform_transition_event_queue()
{
    int err_code = 0;
    err_code = pState->perform_transition_event_queue(this);
    return err_code;
}

int Agent::perform_transition_event_queue_full()
{
    int err_code = 0;
    err_code = pState->perform_transition_event_queue_full(this);
    return err_code;
}

int Agent::perform_transition_event_get_result()
{
    int err_code = 0;
    err_code = pState->perform_transition_event_get_result(this);
    return err_code;
}

int Agent::perform_transition_event_get_result_empty()
{
    int err_code = 0;
    err_code = pState->perform_transition_event_get_result_empty(this);
    return err_code;
}

int Agent::perform_transition_event_error()
{
    int err_code = 0;
    err_code = pState->perform_transition_event_error(this);
    return err_code;
}

int Agent::get_current_state(SM_STATE_ENUM *state)
{
    int err_code = OK;
    if(state == nullptr)
    {
        err_code = SM4A_NULL_POINTER_ERROR;
    }
    if(err_code == OK)
    {
        if(pState == pError)
        {
            *state = SM_STATE_ERROR;
        }else if(pState == pIdle)
        {
            *state = SM_STATE_IDLE;
        }else if(pState == pQueueEmpty)
        {
            *state = SM_STATE_QUEUE_EMPTY;
        }else if(pState == pQueueFull)
        {
            *state = SM_STATE_QUEUE_FULL;
        }else if(pState == pQueuePartyFull)
        {
            *state = SM_STATE_QUEUE_PARTY_FULL;
        }else if(pState == pTerminated)
        {
            *state = SM_STATE_TERMINATED;
        }else
        {
            *state = SM_STATE_MIN;
        }
    }

    return err_code;
}
